home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / basic / bitstuf.com / BITSTUFF.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-08-12  |  1.4 KB  |  83 lines

  1.     page 62, 132
  2.     title Bit test and manipulation routines for BASIC
  3.     subttl By Jim Mack, Editing Services Co.
  4.  
  5. comment |
  6.  
  7.     Implements bit set/clear/test for QB/BC.
  8.  
  9.     Four procedures are declared in BASIC:
  10.  
  11.     DECLARE SUB SetBit (bitnum%, word%)
  12.     DECLARE SUB ClearBit (bitnum%, word%)
  13.     DECLARE SUB ToggleBit (bitnum%, word%)
  14.     DECLARE FUNCTION BitState% (bitnum%, word%)
  15.  
  16.     BITNUM% is the selected bit position, numbered 1 through 16
  17.     WORD% is the 16 bit quantity where the bit resides,
  18.  
  19.     SetBit sets the selected bit to 1
  20.     ClearBit sets it to 0
  21.     ToggleBit changes it to 0 if it is now 1, and vice versa
  22.     BitState returns TRUE (-1) if the bit is set, FALSE (0) if not.
  23.  
  24.     | comment ends
  25.  
  26.     page+
  27.     .model medium, basic
  28.     .code
  29.  
  30. BitCommon    PROC NEAR
  31.  
  32. wd    equ    6[bp]        ; repeat the stack equates from the FAR PROCs
  33. bitnum    equ    8[bp]
  34.  
  35.     mov    bx, bitnum
  36.     mov    cx, [bx]
  37.     dec    cx        ; remove this for bit number range 0-15
  38.     mov    ax, 1
  39.     shl    ax, cl
  40.     mov    bx, wd
  41.     ret
  42.  
  43. BitCommon    ENDP
  44.                                     page+
  45. SetBit        PROC bitnum, wd
  46.  
  47.     call    BitCommon
  48.     or    [bx], ax
  49.     ret
  50.  
  51. SetBit        ENDP
  52.  
  53. ClearBit    PROC bitnum, wd
  54.  
  55.     call    BitCommon
  56.     not    ax
  57.     and    [bx], ax
  58.     ret
  59.  
  60. ClearBit    ENDP
  61.  
  62. ToggleBit    PROC bitnum, wd
  63.  
  64.     call    BitCommon
  65.     xor    [bx], ax
  66.     ret
  67.  
  68. ToggleBit    ENDP
  69.  
  70. BitState    PROC bitnum, wd
  71.  
  72.     call    BitCommon
  73.     xor    cx, cx
  74.     test    [bx], ax
  75.     mov    ax, cx
  76.     jz    @f
  77.     dec    ax
  78. @@:    ret
  79.  
  80. BitState    ENDP
  81.  
  82.     END
  83.